<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>节目审核</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		function cheackAll(obj){
			var isCheck = $(obj).is(":checked");

			$("#contentTable").find("input[type='checkbox']").each(function(){
				$(this).prop("checked", isCheck);
			});
		}
		function batchProcesst(flag){
            var msg="";
            var title="";
            var len=$("#contentTable input[type='checkbox']:checked").length;
            if(len <=0){
                alertx("<spring:message code='tips.mustcheck' />")

            }else{
                if (flag == 'pass') {

                    msg = "<spring:message code='tips.allpass' />"

                    confirmx(msg, function () {
                        var groupList = "";

                        var comment ="";
                        $("#contentTable").find("input[type='checkbox']").each(function () {
                            if ($(this).prop('checked')) {
                                var egId = $(this).attr("id");
                                groupList = groupList + "'" + egId + "',";
                            }
                        });
                        $.ajax({
                            type: "POST",
                            url: "${ctx}/source/eleSourceGroup/approve",
                            data: {groupList: groupList, flag: flag,comment:comment},
                            datatype: "json",
                            success: function (data) {
                                alertx(data.msg, function () {
                                    window.location.reload();
                                });
                            },
                            error: function () {
                                alertx("<spring:message code='tips.contactadmin' />");
                                console.log(e);
                            }
                        });
                    });

                }
                else if (flag == 'reject') {
                    title="<spring:message code='tips.checkcomment' />";
                    msg = "<spring:message code='tips.checkcomment1' />"
                    promptx(title,msg, function (v) {
                        var groupList = "";
                        var txt= $.trim(v);
                        var comment =txt;
                        $("#contentTable").find("input[type='checkbox']").each(function () {
                            if ($(this).prop('checked')) {
                                var egId = $(this).attr("id");
                                groupList = groupList + "'" + egId + "',";
                            }
                        });
                        $.ajax({
                            type: "POST",
                            url: "${ctx}/source/eleSourceGroup/approve",
                            data: {groupList: groupList, flag: flag,comment:comment},
                            datatype: "json",
                            success: function (data) {
                                alertx(data.msg, function () {
                                    window.location.reload();
                                });
                            },
                            error: function () {
                                alertx("<spring:message code='tips.contactadmin' />");
                                console.log(e);
                            }
                        });
                    });
                }
                else {
                    msg = "<spring:message code='tips.delall' />"
                    confirmx(msg, function () {
                        var groupList = "";

                        var comment ="";
                        $("#contentTable").find("input[type='checkbox']").each(function () {
                            if ($(this).prop('checked')) {
                                var egId = $(this).attr("id");
                                groupList = groupList + "'" + egId + "',";
                            }
                        });
                        $.ajax({
                            type: "POST",
                            url: "${ctx}/source/eleSourceGroup/approve",
                            data: {groupList: groupList, flag: flag,comment:comment},
                            datatype: "json",
                            success: function (data) {
                                alertx(data.msg, function () {
                                    window.location.reload();
                                });
                            },
                            error: function () {
                                alertx("<spring:message code='tips.contactadmin' />");
                                console.log(e);
                            }
                        });
                    });
				}



		}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<shiro:hasPermission name="source:eleSourceGroup:check">
		<li class="active"><a href="${ctx}/source/eleSourceGroup/approvelist"><spring:message code='menu.Approval.Approval_ecord.Application_Approval'/></a></li>
		</shiro:hasPermission>
	</ul>
	<div class="control-group" style="margin-bottom:20px;/*background-color:#f5f5f5;*/" >
		<shiro:hasPermission name="source:eleSourceGroup:check">
		<input type="button" value="<spring:message code='Batch.pass'/>" class="btn btn-default btn-lg" onclick="batchProcesst('pass');">
		<input type="button" value="<spring:message code='Batch.rejection'/>" class="btn btn-default btn-lg" onclick="batchProcesst('reject');">
		</shiro:hasPermission>
		<input type="button" value="<spring:message code='Batch.deletion'/>" class="btn btn-default btn-lg" onclick="batchProcesst('delete');">
	<form:form id="searchForm" modelAttribute="eleSourceGroup" action="${ctx}/source/eleSourceGroup/approvelist"
			   method="post" class="breadcrumb form-search" style="float:right;padding-bottom:0px;padding-top:0px;">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
				<input name="isFirst" type="hidden" value="${isFirst}">
		<ul class="ul-form">
            <li>
			<li><label><spring:message code='common.status'/>：</label>
                <form:select path="delFlag" htmlEscape="false"  class="input-medium">
                    <form:option value="5"><spring:message code="all"/></form:option>
                    <form:option value="0"><spring:message code="approved"/></form:option>
                    <form:option value="1"><spring:message code='common.delete'/></form:option>
                    <form:option value="2"><spring:message code='inapproval'/></form:option>
                    <form:option value="3"><spring:message code="rejected"/></form:option>
                </form:select>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="<spring:message code='common.Query'/>"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	</div>
	
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th style="width:40px;text-align:center;"><input type="checkbox" onclick="cheackAll(this)"/></th>
				<th><spring:message code='program.name'/></th>
				<th><spring:message code='common.applicant'/></th>
				<th><spring:message code='common.applicant.time'/></th>
				
				<th><spring:message code="common.approver"/></th>
				<th><spring:message code="common.approver.time"/></th>
                <th><spring:message code="audit.state"/></th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="group">
			<tr>
				<td style="text-align:center;"><input type="checkbox" id="${group.id}" /></td>
				<td> ${group.name} </td>
				<td> ${group.createBy.name} </td>
				<td> <fmt:formatDate value="${group.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/> </td>
                <td> ${group.checkBy.name} </td>
                <td>  <fmt:formatDate value="${group.checkDate}" pattern="yyyy-MM-dd HH:mm:ss"/> </td>
				<td>
                    <c:if test="${group.delFlag == '0'}">
       	<spring:message code="approved"/>
                    </c:if>
                    <c:if test="${group.delFlag == '1'}">
                        <spring:message code='common.delete'/>
                    </c:if>
                    <c:if test="${group.delFlag == '2'}">
                        <spring:message code='inapproval'/>
                    </c:if>
                    <c:if test="${group.delFlag == '3'}">
                        <spring:message code="rejected"/>
                    </c:if>
                </td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>